package com.ebelter.temperaturegun.ui.activity;



import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.nfc.Tag;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebelter.btcomlib.CommonLib;
import com.ebelter.btcomlib.models.bluetooth.products.temperature2.Temperature2Manager;
import com.ebelter.btcomlib.utils.AppUtils;
import com.ebelter.btcomlib.utils.TimeUtils;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.temperaturegun.R;
import com.ebelter.temperaturegun.model.TgManager;
import com.ebelter.temperaturegun.model.app.TemUtils;
import com.ebelter.temperaturegun.ui.view.TemperatureView;
import com.ebelter.temperaturegun.utils.TemGunUtil;


//温度详情展示界面
public class DetailShowActivity extends TBaseActivity {


    public static final String TAG = "DetailShowActivity";

    public static final String TempType="TempType";
    public static final String TestDate="testDate";
    public static final String Value="value";


    public static void openDetailShowActivity(Activity context, String testDate, int tempType, float value){
        Intent intent = new Intent(context, DetailShowActivity.class);
        intent.putExtra(TempType,tempType);
        intent.putExtra(TestDate,testDate);
        intent.putExtra(Value,value);
        context.startActivity(intent);
    }

    private String testDate;
    private int tempType;//(1:耳温,2:额温)
    private float value;


    private ImageView detail_back_iv;
    private TemperatureView temperatureView;
    private TextView detail_nyr_tv;
    private TextView detail_shf_tv;
    private ImageView dl_wenduweizhi_flag_iv;
    private TextView detail_tip_tv;
    private TextView dl_wendu_value_tv;
    private TextView dl_wendu_unit_tv;
    private TextView detail_tip1_tv;
    private TextView detail_tip2_tv;
    private TextView detail_tip3_tv;
    private TextView detail_tip4_tv;
    private TextView main_warring_tv;

    private TextView detai_tv1;
    private TextView detai_tv2;
    private TextView detai_tv3;
    private TextView detai_tv4;


    private int unitModel;

    @Override
    protected int setContentViewId() {
        return R.layout.activity_detail_show;
    }


    @Override
    protected void initData() {


    }

    @Override
    protected void initView() {
        detail_back_iv = findViewById(R.id.detail_back_iv);
        detail_back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        temperatureView = findViewById(R.id.temperatureView);
        detail_nyr_tv = findViewById(R.id.detail_nyr_tv);
        detail_shf_tv = findViewById(R.id.detail_shf_tv);
        dl_wenduweizhi_flag_iv = findViewById(R.id.dl_wenduweizhi_flag_iv);
        dl_wendu_value_tv = findViewById(R.id.dl_wendu_value_tv);
        dl_wendu_unit_tv = findViewById(R.id.dl_wendu_unit_tv);
        detail_tip1_tv = findViewById(R.id.detail_tip1_tv);
        detail_tip2_tv = findViewById(R.id.detail_tip2_tv);
        detail_tip3_tv = findViewById(R.id.detail_tip3_tv);
        detail_tip4_tv = findViewById(R.id.detail_tip4_tv);
        detail_tip_tv = findViewById(R.id.detail_tip_tv);
        main_warring_tv = findViewById(R.id.main_warring_tv);

        detai_tv1 = findViewById(R.id.detai_tv1);
        detai_tv2 = findViewById(R.id.detai_tv2);
        detai_tv3 = findViewById(R.id.detai_tv3);
        detai_tv4 = findViewById(R.id.detai_tv4);


        String local = AppUtils.getLocalStr();

        if (AppUtils.en.equals(local)){
            ViewUtils.setTextSize(detai_tv1,15);
            ViewUtils.setTextSize(detai_tv2,15);
            ViewUtils.setTextSize(detai_tv3,15);
            ViewUtils.setTextSize(detai_tv4,15);

            ViewUtils.setTextSize(detail_tip1_tv,15);
            ViewUtils.setTextSize(detail_tip2_tv,15);
            ViewUtils.setTextSize(detail_tip3_tv,15);
            ViewUtils.setTextSize(detail_tip4_tv,15);
        }


        tempType = getIntent().getIntExtra(TempType,1);
        testDate = getIntent().getStringExtra(TestDate);
        value = getIntent().getFloatExtra(Value,0);
        LogUtils.i(TAG,"--getIntent--tempType="+tempType+" testDate="+testDate+"  value="+value);

        unitModel = TemUtils.getUerUnit();
        setTemperatureViewValue(value);

        long time= TimeUtils.parseFormatter1Time(testDate).getTime();
        ViewUtils.setTextViewStr(detail_nyr_tv,TimeUtils.formatDate_nyr(CommonLib.APPContext,time));
        ViewUtils.setTextViewStr(detail_shf_tv,CommonLib.getString(R.string.celiangshijian)+TimeUtils.formatTime_shf(CommonLib.APPContext,time));


        //(1:耳温,2:额温)
        ViewUtils.setImageResource(dl_wenduweizhi_flag_iv,tempType==1?R.drawable.ic_erwen:R.drawable.ic_ewen);


        //0代表°C 1代表°F
        if (unitModel==0){
            ViewUtils.setTextViewStr(dl_wendu_value_tv,TemGunUtil.getDisTemC(value)+"");
            ViewUtils.setTextViewStr(dl_wendu_unit_tv,"°C");
        }else {
            ViewUtils.setTextViewStr(dl_wendu_value_tv, TemGunUtil.getDisTemF(value)+"");
            ViewUtils.setTextViewStr(dl_wendu_unit_tv,"°F");

            ViewUtils.setTextViewStr(detail_tip1_tv,CommonLib.getString(R.string.tip1F));
            ViewUtils.setTextViewStr(detail_tip2_tv,CommonLib.getString(R.string.tip2F));
            ViewUtils.setTextViewStr(detail_tip3_tv,CommonLib.getString(R.string.tip3F));
            ViewUtils.setTextViewStr(detail_tip4_tv,CommonLib.getString(R.string.tip4F));
        }

        int level = TemUtils.getResultDesc2(value);
        if (level==1){
            //偏低
            ViewUtils.setTextViewStr(main_warring_tv,CommonLib.getString(R.string.piandi));
            ViewUtils.setTextViewStr(detail_tip_tv,R.string.low_tip);
        }else if (level==2){
            //正常
            ViewUtils.setTextViewStr(main_warring_tv,CommonLib.getString(R.string.zhengchang));
            ViewUtils.setTextViewStr(detail_tip_tv,R.string.normal_tip);
        }else if (level==3){
            //偏高
            ViewUtils.setTextViewStr(main_warring_tv,CommonLib.getString(R.string.piangao));
            ViewUtils.setTextViewStr(detail_tip_tv,R.string.high_tip);
        }else {
            ViewUtils.setTextViewStr(detail_tip_tv,"");
        }






    }

    public void setTemperatureViewValue(float value) {
        LogUtils.i(TAG,"----setTemperatureViewValue--value="+value);
        temperatureView.setUnitModel(unitModel);
        temperatureView.setDisplayTemperatureValue(value);
        temperatureView.invalidate();
    }
}
